/* 
 * Enterprise Library Extensions - DI + ORM.
 * Copyright (C) 2006
 *
 * GNU General Public License
 *
 * This program is free software; you can redistribute 
 * it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 */
using System;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace ELE.EnterpriseLibrary.Data.Configuration
{
  /// <summary>
  /// Represents the data from configuration settings that links a query's input or/and results
  /// to a mapping. It is also used to overwrite the parameters of a mapping if necessary.
  /// <para>Example:</para>
  /// <code>
  /// &lt;queries>
  ///    &lt;add name="GetEmployeeById" 
  ///           sql="select id, name, addressId, birthDate from employee e, employee_extra ee where e.id=@Id and ee.employeeId = e.id">
  ///      &lt;mappings>
  ///        &lt;add name="Mapping1" objectId="Employee">
  ///          &lt;bindings>
  ///            ...
  ///          &lt;/bindings>
  ///        &lt;/add>
  ///      &lt;/mappings>
  ///    &lt;/add>
  /// &lt;/queries>
  /// </code>
  /// <para>In this case, "Mapping1" makes a reference to a mapping defined with that name in 
  /// the mappings section of the configuration (<see cref="MappingQueryData"/>) that contains 
  /// a mapping definition for the "Employee" object.</para>
  /// </summary>
  public class MappingReferenceData : NamedConfigurationElement
  {
    private const string objectIdProperty = "objectId";
    private const string bindingsProperty = "bindings";
    /// <summary>
    /// Default empty reference.
    /// </summary>
    public MappingReferenceData()
    {
    }
    /// <summary>
    /// The id of the object that is to be mapped from the query's inputs or results.
    /// </summary>
    [ConfigurationProperty(objectIdProperty, IsRequired = true)]
    public string ObjectId
    {
      get { return (string)base[objectIdProperty]; }
      set { base[objectIdProperty] = value; }
    }
    /// <summary>
    /// A collection of settings that overwrite the bindings of the linked object.
    /// </summary>
    [ConfigurationProperty(bindingsProperty, IsRequired = false)]
    public NamedElementCollection<PropertyBindingOverwriteData> OverwriteBindings
    {
      get
      {
        return (NamedElementCollection<PropertyBindingOverwriteData>)base[bindingsProperty];
      }
    }
  }
}
